from collections import namedtuple
from collections.abc import Callable
import json
from typing import Any


class Position:
    def __init__(self, x: float, y: float):
        self.x, self.y = x, y


class DefaultResponse:
    def __init__(self, success: bool, message: str):
        self.success, self.message = success, message


class ActorInfo:
    def __init__(self, name: str, type: str):
        self.name, self.type = name, type


class ActorState:
    def __init__(self, position: Position, speed: float, rotation: float):
        self.position, self.speed, self.rotation = position, speed, rotation


class Path:
    def __init__(self, nextPositionIndex: int, pathPoints: list):
        self.nextPositionIndex, self.pathPoints = nextPositionIndex, pathPoints


class Command:
    def __init__(self, type: str, args):
        self.type, self.args = type, args

class MoveCommand:
    def __init__(self, start: Position, destination: Position, operatorID: str):
        self.type, self.args = "Move", {
            "StartPosition": start, "TargetPosition": destination, "OperatorUUID": operatorID}
        
class StopCommand:
    def __init__(self):
        self.type, self.args = "Move", {}

class ActorInfoResponse:
    def __init__(self, uuid: str, info: ActorInfo):
        self.uuid, self.info = uuid, info


class ActorStateResponse:
    def __init__(self, uuid: str, state: ActorState):
        self.uuid, self.state = uuid, state


class DefaultEncoder(json.JSONEncoder):
    def default(self, o):
        return o.__dict__


def DefaultDecoder(dic):
    return namedtuple('X', dic.keys())(*dic.values())
